package com.ruoyi.production.controller;

import java.io.InputStream;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.OperationSteps;
import com.ruoyi.production.service.IOperationStepsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 工序设置Controller
 * 
 * @author admin
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/production/steps")
public class OperationStepsController extends BaseController
{
    @Autowired
    private IOperationStepsService operationStepsService;

    /**
     * 查询工序设置列表
     */
    @PreAuthorize("@ss.hasPermi('production:steps:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperationSteps operationSteps)
    {
        startPage();
        List<OperationSteps> list = operationStepsService.selectOperationStepsList(operationSteps);
        return getDataTable(list);
    }

    /**
     * 导出工序设置列表
     */
    @PreAuthorize("@ss.hasPermi('production:steps:export')")
    @Log(title = "工序设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationSteps operationSteps)
    {
        List<OperationSteps> list = operationStepsService.selectOperationStepsList(operationSteps);
        ExcelUtil<OperationSteps> util = new ExcelUtil<OperationSteps>(OperationSteps.class);
        util.exportExcel(response, list, "工序设置数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<OperationSteps> util = new ExcelUtil<OperationSteps>(OperationSteps.class);
        util.importTemplateExcel(response, "工序设置数据");
    }
    /**
     * 导入数据
     */
    @Log(title = "工序设置", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('production:Operationsteps:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<OperationSteps> util = new ExcelUtil<OperationSteps>(OperationSteps.class);
        InputStream inputStream = file.getInputStream();
        List<OperationSteps> list = util.importExcel(inputStream );
        inputStream.close();
        int count = operationStepsService.batchInsertOperationSteps(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }


    /**
     * 获取工序设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:steps:query')")
    @GetMapping(value = "/{stepsId}")
    public AjaxResult getInfo(@PathVariable("stepsId") Long stepsId)
    {
        return success(operationStepsService.selectOperationStepsByStepsId(stepsId));
    }

    /**
     * 新增工序设置
     */
    @PreAuthorize("@ss.hasPermi('production:steps:add')")
    @Log(title = "工序设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationSteps operationSteps)
    {
        return toAjax(operationStepsService.insertOperationSteps(operationSteps));
    }


    /**
     * 修改工序设置
     */
    @PreAuthorize("@ss.hasPermi('production:steps:edit')")
    @Log(title = "工序设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationSteps operationSteps)
    {
        return toAjax(operationStepsService.updateOperationSteps(operationSteps));
    }

    /**
     * 删除工序设置
     */
    @PreAuthorize("@ss.hasPermi('production:steps:remove')")
    @Log(title = "工序设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stepsIds}")
    public AjaxResult remove(@PathVariable Long[] stepsIds)
    {
        return toAjax(operationStepsService.deleteOperationStepsByStepsIds(stepsIds));
    }
}
